package br.unifor.cct.mia.initialize;

import br.unifor.cct.mia.evolutionary.Genotype;
import br.unifor.cct.mia.ga.Ga;
import br.unifor.cct.mia.util.Methods;

public class FixedSizeRandomInitialize implements Initialize {

	public Object execute(Object value) {	
		Object[] o = (Object[]) value;		
		int totalSize = ((Integer)(o)[0]).intValue();
		Ga Ga = (Ga)o[1];
		
		Ga.population = new Genotype[Ga.configurations.getPopsize() + 1];
        
        for (int i = 0; i < Ga.configurations.getPopsize()+1; i++) {
        	
        	Ga.population[i] = new Genotype(Ga.configurations);        	
        	Ga.population[i].setFitness(0);
        	Ga.population[i].setSelectProbability(0);                 
            
            for (int j = 0; j < Ga.configurations.getNvars(); j++) {           	
            	((Genotype)Ga.population[i]).setLower(0, j);
            	((Genotype)Ga.population[i]).setUpper(totalSize, j); 	       
            	((Genotype)Ga.population[i]).setInteger(true, j);            	
            	((Genotype)Ga.population[i]).setGene(Methods.randIntValue(0,totalSize),j);            	
            }            
        }
	        
		return Ga.population;
	}

}
